﻿using FluentNHibernate.Mapping;
using Konekcija.Core.Reporting.Dto.Application.Crm;

namespace Konekcija.Core.Reporting.Mappings.Crm
{
    public class AccountTypeMap : ClassMap<AccountType>
    {
        public AccountTypeMap()
        {
            Schema("crm");
            Table("AccountTypes");

            Id(x => x.Id).GeneratedBy.GuidComb().Not.Nullable();
            Map(x => x.Type).Nullable();
            Map(x => x.DateCreated).Nullable();

            HasMany(x => x.Accounts)
                .LazyLoad()
                .Inverse()
                .AsBag()
                .Key(k => k.Not.Nullable())
                .KeyColumn("AccountTypeId")
                .Fetch.Join()
                .ForeignKeyCascadeOnDelete()
                .Cascade.Delete();
        }
    }
}